home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Network Support Library
/
RoseWare - Network Support Library.iso
/
apidev
/
q.arc
/
Q.C
next >
Wrap
Text File
|
1989-11-12
|
5KB
|
179 lines
/**************************************************************************/
/* Q */
/* by Morgan Adair */
/* */
/* Displays a list of print jobs for specified print queue(s) */
/**************************************************************************/
#include <nit.h>
#include <nitq.h>
main(argc, argv)
int argc;
char *argv[];
{
int cCode;
int queueFound = 0;
char serverName[48];
WORD connectionID;
char searchName[48];
long objectID = -1;
char objectName[48];
int objectType;
char objectHasProperties;
char objectFlag;
char objectSecurity;
if (argc < 2) {
/* no command line arguments, use default file server */
connectionID = GetDefaultConnectionID();
GetFileServerName(connectionID, serverName);
} else {
/* a file server was specified, look for queues on it */
strcpy(serverName, argv[1]);
if (!(cCode = GetConnectionID(serverName, &connectionID)))
SetPreferredConnectionID(connectionID);
else {
printf("No connection to server %s\n", serverName);
Syntax();
exit(-1);
}
}
if (argc == 3) {
/* both a file server name and print queue name were
specified, handle just the one queue */
strupr(argv[2]);
if (!(cCode = ScanBinderyObject(argv[2], OT_PRINT_QUEUE,
&objectID, objectName,
&objectType, &objectHasProperties,
&objectFlag, &objectSecurity))) {
printf("Queue Job # \t\tOwner[Station #] \tJob Size (bytes)\n\n");
CheckQueue(objectName, objectID);
} else {
printf("Queue %s not found\n", argv[2]);
Syntax();
exit(-1);
}
} else {
/* no queue name was specified, handle all queues on
preferred file server */
strcpy(searchName, "*");
do { /* While finding queues on the file server */
cCode = ScanBinderyObject(searchName, OT_PRINT_QUEUE,
&objectID, objectName,
&objectType, &objectHasProperties,
&objectFlag, &objectSecurity);
if (!cCode) { /* Found a queue object */
if (!queueFound) { /* First one I found */
printf("Queue Job # \t\tOwner[Station #] \tJob Size (bytes)\n\n");
queueFound = 1;
}
CheckQueue(objectName, objectID);
} else if (!queueFound) { /* Didn't find any queues */
printf("No queues found on server %s\n", serverName);
Syntax();
exit(-1);
}
} while (!cCode);
}
}
CheckQueue(queueName, queueID) /* list print jobs on specified queue */
char queueName[48];
long queueID;
{
#define MAX_JOB_NUMS 250
int cCode;
int jobCount;
int i;
int jobNumberList[MAX_JOB_NUMS];
JobStruct job;
char clientName[48];
int clientType;
long fileSize;
char outString[80];
char active[10];
char errMsg[25];
if (cCode = GetQueueJobList(queueID, &jobCount,
jobNumberList, MAX_JOB_NUMS)) {
/* an error getting the queue's job list */
switch (cCode) {
case 150: strcpy(errMsg, "Server out of memory");
break;
case 211: strcpy(errMsg, "No rights to queue");
break;
default: strcpy(errMsg, "Error getting job list");
}
sprintf(outString, "%-10s %-25s\n", queueName, errMsg);
} else if (jobCount == 0)
/* GetQueueJobList did not return error, but no jobs in queue */
sprintf(outString, "%-10s %-25s\n", queueName, "No jobs");
else {
/* GetQueueJobList succeeded, and jobs in queue */
for (i=0; i<=jobCount-1; i++) {
/* the next three calls must succeed before displaying print
job data */
cCode = ReadQueueJobEntry(queueID, jobNumberList[i], &job);
cCode = (cCode | GetBinderyObjectName(job.clientIDNumber,
clientName,
&clientType));
cCode = (cCode | GetQueueJobsFileSize(queueID,
jobNumberList[i],
&fileSize));
if (i>0)
/* display queue name only with first job in list */
strcpy(queueName, "");
if (cCode)
sprintf(outString, "%-10s %-5d\n", queueName,
jobNumberList[i], "\tError getting data on job\n");
else {
/* show whether job is active */
if (job.serverIDNumber == 0L)
strcpy(active, "");
else
strcpy(active, "(active)");
sprintf(outString, "%-10s %-5d%8s %18s[%d] \t%10ld\n",
queueName, jobNumberList[i], active, clientName,
job.clientStation, fileSize);
}
printf(outString);
}
strcpy(outString, "");
}
printf(outString);
printf("\n");
}
Syntax()
{
printf("\tSyntax: q <servername> <queuename>\n\n");
}